<template>

	<view>

		<view>
			<view style="margin-left: 20px;margin-top: 20px;">
				<view>基本资料</view>
			</view>

			<view style="margin-left: 20px;margin-right: 20px;">

				<view class="uni-flex uni-row bg-white"
					style="margin-top: 20px;display: flex; justify-content: center; flex-direction: row;align-items: center;">
					<view class="flex-left">系统账号</view>
					<view class="flex-right">
						<uni-easyinput disabled :value="user.account" placeholder="请输入内容" style="margin: 5px;">
						</uni-easyinput>
					</view>
				</view>

				<view class="uni-flex uni-row bg-white"
					style="margin-top: 20px;display: flex; justify-content: center; flex-direction: row;align-items: center;">
					<view class="flex-left">真实姓名</view>
					<view class="flex-right">
						<uni-easyinput placeholder="请输入内容" style="margin: 5px;" :value="user.name" v-model="user.name">
						</uni-easyinput>
					</view>
				</view>

				<view class="uni-flex uni-row bg-white"
					style="margin-top: 20px;display: flex; justify-content: center; flex-direction: row;align-items: center;">
					<view class="flex-left">邮箱地址</view>
					<view class="flex-right">
						<uni-easyinput placeholder="请输入内容" style="margin: 5px;" :value="user.email"
							v-model="user.email"></uni-easyinput>
					</view>
				</view>

				<view class="uni-flex uni-row bg-white"
					style="margin-top: 20px;display: flex; justify-content: center; flex-direction: row;align-items: center;">
					<view class="flex-left">手机号码</view>
					<view class="flex-right">
						<uni-easyinput placeholder="请输入内容" style="margin: 5px;" :value="user.phone"
							v-model="user.phone"></uni-easyinput>
					</view>
				</view>

			</view>
		</view>

		<view
			style="bottom: 10px;display: flex;position: fixed;width: 100%;align-items: center;justify-content: center;flex-direction: row;">
			<button class="button" style="width: 60%;" type="primary" @click="Submit()">保存信息</button>
		</view>


	</view>

</template>

<script>
	export default {
		data() {
			return {
				user: [],
				userEntity: this.StorageCache('user')
			}

		},
		onLoad() {
			this.Init()
		},
		methods: {
			Init() {

				this.checkLogin()

				this.user = []


				uni.request({
					url: this.url+'AppGetUser',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					method: 'POST',
					dataType: 'json',
					data: {
						userId: this.userEntity.sid,

					},
					success: (res) => {

						if (res.statusCode == 200) {

							this.user = res.data


						}
					},
					complete: (res) => {

					}
				});


			},
			Submit() {
				if (!this.checkEmail(this.user.email)) {
					uni.showToast({
						title: "邮箱格式不正确",
						icon: 'none'
					});
					return false;
				}
				if (!this.checkMobile(this.user.phone)) {
					uni.showToast({
						title: "联系方式格式不正确",
						icon: 'none'
					});
					return false;
				}


				uni.request({
					url: this.url+'AppUpdateBasicUser',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					method: 'POST',
					dataType: 'json',
					data: {
						sid: this.user.sid,
						name: this.user.name,
						email: this.user.email,
						phone: this.user.phone,

					},
					success: (res) => {

						if (res.statusCode == 200) {
							uni.showToast({
								title: "修改成功"
							});
						}
					},
					complete: (res) => {
	
					}
				});


			},
			//校验邮箱格式
			checkEmail: function(email) {
				return RegExp(
						/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/)
					.test(email);
			},
			//校验手机格式
			checkMobile: function(mobile) {
				return RegExp(/^1[34578]\d{9}$/).test(mobile);
			},
			checkPassword:function(passWord){
				return RegExp(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/).test(passWord)
			}



		}
	}
</script>

<style>
	.flex-left {
		width: 25%;
		text-align: center;
		height: 55px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.flex-right {
		width: 80%;
		text-align: center;
		height: 55px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.flex-item {
		width: 33.3%;

		text-align: center;
		height: 55px;
		display: flex;
		align-items: center;
		justify-content: center;

	}

	.bg-white {
		background-color: #FFFFFF;
		border: 1px solid #BEBEBE;
	}
</style>
